<!DOCTYPE html>
<html lang="zh-cn">
<head>
  
    <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=KOZafwuaDasEedEenI5aTy8aXH0epbm6VUJ0v3vsT_Q1"/>
<link id="MainCss" type="text/css" rel="stylesheet" href="/skins/ThinkInside/bundle-ThinkInside.css?v=RRjf6pEarGnbXZ86qxNycPfQivwSKWRa4heYLB15rVE1"/>
<link type="text/css" rel="stylesheet" href="/blog/customcss/428549.css?v=%2fam3bBTkW5NBWhBE%2fD0lcyJv5UM%3d"/>

</head>
<body>
<a name="top"></a>

<div id="page_begin_html"></div><script>load_page_begin_html();</script>

<div id="topics">
	<div class = "post">
		<h1 class = "postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/frankdeng/p/9403883.html">Kafka（二）CentOS7.5搭建Kafka2.11-1.1.0集群与简单测试</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="blogpost-body"><h2 id="blogTitle0">一、下载</h2>
<p>下载地址：</p>
<p><a href="http://kafka.apache.org/downloads.html" target="_blank">http://kafka.apache.org/downloads.html</a>&nbsp; &nbsp; 我这里下载的是Scala 2.11对应的&nbsp;<a href="https://archive.apache.org/dist/kafka/1.1.0/kafka_2.11-1.1.0.tgz">kafka_2.11-1.1.0.tgz</a></p>
<p><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727125005109-1259300199.png" alt="" /></p>
<h2>二、kafka安装</h2>
<h4>集群规划</h4>
<table style="background-color: #36c897;" border="0">
<tbody>
<tr>
<td style="text-align: center;">IP</td>
<td>节点名称</td>
<td>Kafka</td>
<td>Zookeeper</td>
<td>Jdk</td>
<td>Scala</td>
</tr>
<tr>
<td>192.168.100.21</td>
<td>node21</td>
<td>Kafka</td>
<td>Zookeeper</td>
<td>Jdk</td>
<td>Scala</td>
</tr>
<tr>
<td>192.168.100.22</td>
<td>node22</td>
<td>Kafka</td>
<td>Zookeeper</td>
<td>Jdk</td>
<td>Scala</td>
</tr>
<tr>
<td>192.168.100.23</td>
<td>node23</td>
<td>Kafka</td>
<td>Zookeeper</td>
<td>Jdk</td>
<td>Scala</td>
</tr>
</tbody>
</table>
<p>Zookeeper集群安装参考：&nbsp;<a id="post_title_link_9018177" href="https://www.cnblogs.com/frankdeng/p/9018177.html" target="_blank">CentOS7.5搭建Zookeeper3.4.12集群与命令行操作</a></p>
<h3 id="blogTitle3">2.1 上传解压缩</h3>
<div class="cnblogs_code">
<pre>[admin@node21 software]$ tar zxvf kafka_2.11-1.1.0.tgz -C /opt/module/<span><br /></span></pre>
</div>
<h3>2.2 创建日志目录</h3>
<div class="cnblogs_code">
<pre>[admin@node21 software]$ cd /opt/module/kafka_2.11-1.1.0<span>
[admin@node21 kafka_2.11-1.1.0]$ mkdir logs</span></pre>
</div>
<h3 id="blogTitle4">2.3 修改配置文件</h3>
<p>进入kafka的安装配置目录</p>
<div class="cnblogs_code">
<pre>[admin@node21 kafka_2.11-1.1.0]$ cd config/<span>
[admin@node21 config]$ vi server.properties</span></pre>
</div>
<p>主要关注：<strong>server.properties</strong>&nbsp;这个文件即可，发现在配置目录下也有Zookeeper文件，我们可以根据Kafka内置的zk集群来启动，但是建议使用独立的zk集群。</p>
<p><span style="color: #ff0000;">server.properties</span>（<strong>broker.id和listeners每个节点都不相同</strong>）</p>
<div class="cnblogs_code">
<pre><span>#是否允许删除topic，默认false不能手动删除
<span style="color: #ff0000;">delete.topic.enable=true</span><span>
#当前机器在集群中的唯一标识，和zookeeper的myid性质一样
broker.id=<span style="color: #ff0000;">0</span><span>
#当前kafka服务侦听的地址和端口，端口默认是9092
listeners = PLAINTEXT://<span style="color: #ff0000;">192.168.100.21</span>:9092
<span>#这个是borker进行网络处理的线程数
num.network.threads=3<span>
#这个是borker进行I/<span>O处理的线程数
num.io.threads=8<span>
#发送缓冲区buffer大小，数据不是一下子就发送的，先会存储到缓冲区到达一定的大小后在发送，能提高性能
socket.send.buffer.bytes=102400<span>
#kafka接收缓冲区大小，当数据到达一定大小后在序列化到磁盘
socket.receive.buffer.bytes=102400<span>
#这个参数是向kafka请求消息或者向kafka发送消息的请请求的最大数，这个值不能超过java的堆栈大小
socket.request.max.bytes=104857600<span>
#消息日志存放的路径
log.dirs=/opt/module/kafka_2.11-1.1.0/<span>logs
#默认的分区数，一个topic默认1个分区数
num.partitions=1<span>
#每个数据目录用来日志恢复的线程数目
num.recovery.threads.per.data.dir=1<span>
#默认消息的最大持久化时间，168小时，7天
log.retention.hours=168<span>
#这个参数是：因为kafka的消息是以追加的形式落地到文件，当超过这个值的时候，kafka会新起一个文件
log.segment.bytes=1073741824<span>
#每隔300000毫秒去检查上面配置的log失效时间
log.retention.check.interval.ms=300000<span>
#是否启用log压缩，一般不用启用，启用的话可以提高性能
log.cleaner.enable=false<span>
#设置zookeeper的连接端口
<span style="color: #ff0000;">zookeeper.connect=node21:2181,node22:2181,node23:2181</span><span>
#设置zookeeper的连接超时时间
zookeeper.connection.timeout.ms=6000</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
</div>
<h3 id="blogTitle5">2.4分发安装包到其他节点</h3>
<div class="cnblogs_code">
<pre>[admin@node21 module]$ scp -r kafka_2.11-1.1.0 admin@node22:/opt/module/<span>
[admin@node21 module]$ scp -r kafka_2.11-1.1.0 admin@node23:/opt/module/</span></pre>
</div>
<p><strong>修改node22，node23节点kafka配置文件conf/server.properties里面的</strong>broker.id和listeners的值。</p>
<h3 id="blogTitle7">2.5 添加环境变量</h3>
<div class="cnblogs_code">
<pre>[admin@node21 module]$ vi /etc/<span>profile
#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka_2.11-1.1.0<br />export PATH=$PATH:$KAFKA_HOME/bin</span></pre>
</div>
<p>保存使其立即生效</p>
<div class="cnblogs_code">
<pre>[admin@node21 module]$ &nbsp;source /etc/profile</pre>
</div>
<h2 id="blogTitle8">三、kafka集群启动</h2>
<h3 id="blogTitle9">3.1 首先启动zookeeper集群</h3>
<p>所有zookeeper节点都需要执行</p>
<div class="cnblogs_code">
<pre><span>[admin@node21 ~]$ zkServer.sh start<br /></span></pre>
</div>
<h3 id="blogTitle10">3.2 后台启动Kafka集群服务</h3>
<p>所有Kafka节点都需要执行</p>
<div class="cnblogs_code">
<pre>[admin@node21 kafka_2.11-1.1.0]$ bin/kafka-server-start.sh config/server.properties &amp;</pre>
</div>
<h2 id="blogTitle8">四、kafka命令行操作</h2>
<p><span style="color: #ff0000;">kafka-broker-list：node21:9092,node22:9092,node23:9092</span></p>
<p><span style="color: #ff0000;">zookeeper.connect-list： node21:2181,node22:2181,node23:2181</span></p>
<h3>4.1 创建新topic&nbsp;</h3>
<div class="cnblogs_code">
<pre>[admin@node22 kafka_2.11-1.1.0]$ bin/kafka-<span>topics.sh
Create, delete, describe, or change a topic.
Option                                   Description                            
------                                   -----------                            
--<span>alter                                  Alter the number of partitions,        
                                           replica assignment, and/<span>or           
                                           configuration for<span> the topic.         
--config &lt;String: name=value&gt;            A topic configuration override for<span> the 
                                           topic being created or altered.The   
                                           following is<span> a list of valid         
                                           configurations:                      
                                             cleanup.policy                        
                                             compression.type                      
                                             delete.retention.ms                   
                                             file.delete.delay.ms                  
                                             flush.messages                        
                                             flush.ms                              
                                             follower.replication.throttled.       
                                           replicas                             
                                             index.interval.bytes                  
                                             leader.replication.throttled.replicas 
                                             max.message.bytes                     
                                             message.format.version                
                                             message.timestamp.difference.max.ms   
                                             message.timestamp.type                
                                             min.cleanable.dirty.ratio             
                                             min.compaction.lag.ms                 
                                             min.insync.replicas                   
                                             preallocate                           
                                             retention.bytes                       
                                             retention.ms                          
                                             segment.bytes                         
                                             segment.index.bytes                   
                                             segment.jitter.ms                     
                                             segment.ms                            
                                             unclean.leader.election.enable        
                                         See the Kafka documentation for<span> full   
                                           details on the topic configs.        
<span style="color: #ff0000;">--create  </span>                               Create a new<span> topic.                    
<span style="color: #ff0000;">--</span><span><span style="color: #ff0000;">delete </span>                                Delete a topic                         
--delete-config &lt;String: name&gt;           A topic configuration override<span> to be   
                                           removed for<span> an existing topic (see   
                                           the list of configurations under the 
                                           --<span>config option).                    
<span style="color: #ff0000;">--describe</span>                               List details for<span> the given topics.     
--disable-rack-<span>aware                     Disable rack aware replica assignment  
--<span>force                                  Suppress console prompts               
<span style="color: #ff0000;">--</span><span><span style="color: #ff0000;">help  </span>                                 Print usage information.               
--if-exists                              if set<span> when altering or deleting       
                                           topics, the action will only execute 
                                           if<span> the topic exists                  
--if-not-exists                          if set<span> when creating topics, the       
                                           action will only execute if<span> the      
                                           topic does not already exist         
<span style="color: #ff0000;">--</span><span><span style="color: #ff0000;">list </span>                                  List all available topics.             
<span style="color: #ff0000;">--partitions</span> &lt;Integer: # of partitions&gt;  The number of partitions for<span> the topic 
                                           being created or altered (WARNING:   
                                           If partitions are increased for<span> a    
                                           topic that has a key, the partition  
                                           logic or ordering of the messages    
                                           will be affected                     
--replica-assignment &lt;String:            A list of manual partition-to-<span>broker   
  broker_id_for_part1_replica1 :           assignments for<span> the topic being      
  broker_id_for_part1_replica2 ,           created or altered.                  
  broker_id_for_part2_replica1 :                                                
  broker_id_for_part2_replica2 , ...&gt;                                           
<span style="color: #ff0000;">--replication-factor</span> &lt;Integer:           The replication factor for<span> each        
  replication factor&gt;                      partition in<span> the topic being created.
<span style="color: #ff0000;">--topic</span> &lt;String: topic&gt;<span>                  The topic to be create, alter or       
                                           describe. Can also accept a regular  
                                           expression except for --<span>create option
--topics-with-overrides                  if set<span> when describing topics, only    
                                           show topics that have overridden     
                                           configs                              
--unavailable-partitions                 if set<span> when describing topics, only    
                                           show partitions whose leader is<span> not  
                                           available                            
--under-replicated-partitions            if set<span> when describing topics, only    
                                           show under replicated partitions     
<span style="color: #ff0000;">--zookeeper</span> &lt;String: hosts&gt;              <span style="color: #ff0000;">REQUIRED</span>: The connection string for<span>    
                                           the zookeeper connection in<span> the form 
                                           host:port. Multiple hosts can be     
                                           given to allow fail-over. </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
</div>
<p>在node21节点上创建一个新的Topic</p>
<div class="cnblogs_code">
<pre>[admin@node21 kafka_2.11-1.1.0]$ bin/kafka-topics.sh --create --zookeeper node21:2181,node22:2181,node23:2181 --replication-factor 3 --partitions 3 --topic TestTopic</pre>
</div>
<p class="20"><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727182808985-1592684258.png" alt="" /></p>
<p class="20">选项说明：</p>
<p class="20">--topic 定义topic名</p>
<p class="20">--replication-factor &nbsp;定义副本数</p>
<p class="20">--partitions &nbsp;定义分区数</p>
<h3 id="blogTitle12">4.2 查看topic副本信息</h3>
<div class="cnblogs_code">
<pre>[admin@node21 kafka_2.11-1.1.0]$ bin/kafka-topics.sh --describe --zookeeper node21:2181,node22:2181,node23:2181 --topic TestTopic</pre>
</div>
<p><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727183225173-1816266043.png" alt="" /></p>
<h3>4.3 查看已经创建的topic信息</h3>
<div class="cnblogs_code">
<p>[admin@node21 kafka_2.11-1.1.0]$ kafka-topics.sh --list --zookeeper node21:2181,node22:2181,node23:2181</p>
</div>
<p><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727183356332-2031597496.png" alt="" /></p>
<h3 id="blogTitle14">4.4 测试生产者发送消息</h3>
<div class="cnblogs_code">
<pre>[admin@node22 kafka_2.11-1.1.0]$ bin/kafka-console-<span>producer.sh 
Read data from<span> standard input and publish it to Kafka.
Option                                   Description                            
------                                   -----------                            
--batch-size &lt;Integer: size&gt;             Number of messages to send in<span> a single 
                                           batch if<span> they are not being sent     
                                           synchronously. (default: 200<span>)        
<span style="color: #ff0000;">--broker-list</span> &lt;String: broker-list&gt;     <span style="color: #ff0000;"> REQUIRED</span>: The broker list string in<span>    
                                           the form <span style="color: #ff0000;">HOST1:PORT1,HOST2:PORT2</span>.    
--compression-codec [String:             The compression codec: either 'none'<span>,  
  compression-codec]                       'gzip', 'snappy', or 'lz4'<span>.If        
                                           specified without value, then it     
                                           defaults to 'gzip'                   
--key-serializer &lt;String:                The class<span> name of the message encoder  
  encoder_class&gt;                           implementation to use for<span>            
                                           serializing keys. (default<span>: kafka.   
                                           serializer.DefaultEncoder)           
--line-reader &lt;String: reader_class&gt;     The class name of the class to use for<span> 
                                           reading lines from standard in<span>. By   
                                           default each line is read as<span> a       
                                           separate message. (default<span>: kafka.   
                                           tools.                               
                                           ConsoleProducer$LineMessageReader)   
--max-block-ms &lt;<span>Long: max block on       The max time that the producer will    
  send&gt;                                    block for<span> during a send request      
                                           (default: 60000<span>)                     
--max-memory-bytes &lt;<span>Long: total memory   The total memory used by the producer  
  in bytes&gt;<span>                                to buffer records waiting to be sent 
                                           to the server. (default: 33554432<span>)   
--max-partition-memory-bytes &lt;Long:      The buffer size allocated for<span> a        
  memory in bytes per partition&gt;<span>           partition. When records are received 
                                           which are smaller than this<span> size the 
                                           producer will attempt to             
                                           optimistically group them together   
                                           until this size is<span> reached.          
                                           (default: 16384<span>)                     
--message-send-max-retries &lt;Integer&gt;<span>     Brokers can fail receiving the message 
                                           for<span> multiple reasons, and being      
                                           unavailable transiently is<span> just one  
                                           of them. This property specifies the 
                                           number of retires before the         
                                           producer give up and drop this<span>       
                                           message. (default: 3<span>)                
--metadata-expiry-ms &lt;Long: metadata     The period of time in<span> milliseconds     
  expiration interval&gt;<span>                     after which we force a refresh of    
                                           metadata even if we haven't seen any 
                                           leadership changes. (default: 300000<span>)
<span style="color: #ff0000;">--old-</span><span><span style="color: #ff0000;">producer</span>                           Use the old producer implementation.   
--producer-property &lt;String:             A mechanism to pass user-<span>defined       
  producer_prop&gt;                           properties in the form key=<span>value to  
                                           the producer.                        
--producer.config &lt;String: config file&gt;<span>  Producer config properties file. Note  
                                           that [producer-<span>property] takes       
                                           precedence over this<span> config.         
--property &lt;String: prop&gt;                A mechanism to pass user-<span>defined       
                                           properties in the form key=<span>value to  
                                           the message reader. This allows      
                                           custom configuration for a user-<span>     
                                           defined message reader.              
--queue-enqueuetimeout-ms &lt;Integer:      Timeout for event enqueue (default<span>:    
  queue enqueuetimeout ms&gt;                 2147483647<span>)                          
--queue-size &lt;Integer: queue_size&gt;       If set and the producer is running in<span>  
                                           asynchronous mode, this<span> gives the    
                                           maximum amount of  messages will     
                                           queue awaiting sufficient batch      
                                           size. (default: 10000<span>)               
--request-required-acks &lt;<span>String:         The required acks of the producer      
  request required acks&gt;                   requests (default: 1<span>)                
--request-timeout-ms &lt;<span>Integer: request   The ack timeout of the producer        
  timeout ms&gt;                              requests. Value must be non-<span>negative 
                                           and non-zero (default: 1500<span>)         
--retry-backoff-ms &lt;Integer&gt;<span>             Before each retry, the producer        
                                           refreshes the metadata of relevant   
                                           topics. Since leader election takes  
                                           a bit of time, this<span> property         
                                           specifies the amount of time that    
                                           the producer waits before refreshing 
                                           the metadata. (default: 100<span>)         
--socket-buffer-size &lt;Integer: size&gt;<span>     The size of the tcp RECV size.         
                                           (default: 102400<span>)                    
--sync                                   If set<span> message send requests to the    
                                           brokers are synchronously, one at a  
                                           time as<span> they arrive.                 
--timeout &lt;Integer: timeout_ms&gt;          If set and the producer is running in<span>  
                                           asynchronous mode, this<span> gives the    
                                           maximum amount of time a message     
                                           will queue awaiting sufficient batch 
                                           size. The value is given in<span> ms.      
                                           (default: 1000<span>)                      
<span style="color: #ff0000;">--topic</span> &lt;String: topic&gt;<span><span style="color: #ff0000;">                  REQUIRED</span>: The topic id to produce      
                                           messages to.                         
--value-serializer &lt;String:              The class<span> name of the message encoder  
  encoder_class&gt;                           implementation to use for<span>            
                                           serializing values. (default<span>: kafka. 
                                           serializer.DefaultEncoder)  </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
</div>
<p>在node21上生产消息</p>
<div class="cnblogs_code">
<p>[admin@node21 kafka_2.11-1.1.0]$ bin/kafka-console-producer.sh --broker-list node21:9092,node22:9092,node23:9092 --topic TestTopic</p>
</div>
<h3><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727183647293-914419095.png" alt="" /></h3>
<h3 id="blogTitle15">4.5 测试消费者消费消息</h3>
<div class="cnblogs_code">
<pre>[admin@node22 kafka_2.11-1.1.0]$ bin/kafka-console-<span>consumer.sh
The console consumer is a tool that reads data from<span> Kafka and outputs it to standard output.
Option                                   Description                            
------                                   -----------                            
--blacklist &lt;String: blacklist&gt;          Blacklist of topics to exclude from<span>    
                                           consumption.                         
--bootstrap-server &lt;String: server to    <span style="color: #ff0000;">REQUIRED</span> (unless old consumer is<span>       
  connect to&gt;<span>                              used): The server to connect to.     
--consumer-property &lt;String:             A mechanism to pass user-<span>defined       
  consumer_prop&gt;                           properties in the form key=<span>value to  
                                           the consumer.                        
--consumer.config &lt;String: config file&gt;<span>  Consumer config properties file. Note  
                                           that [consumer-<span>property] takes       
                                           precedence over this<span> config.         
--csv-reporter-enabled                   If set<span>, the CSV metrics reporter will  
                                           be enabled                           
--delete-consumer-offsets                If specified, the consumer path in<span>     
                                           zookeeper is<span> deleted when starting up
--enable-systest-<span>events                  Log lifecycle events of the consumer   
                                           in<span> addition to logging consumed      
                                           messages. (This is specific for<span>      
                                           system tests.)                       
--formatter &lt;String: class&gt;              The name of a class to use for<span>         
                                           formatting kafka messages for<span>        
                                           display. (default<span>: kafka.tools.      
                                           DefaultMessageFormatter)             
--from-<span>beginning                         If the consumer does not already have  
                                           an established offset to consume     
                                           from<span>, start with the earliest        
                                           message present in<span> the log rather    
                                           than the latest message.             
--group &lt;String: consumer group id&gt;<span>      The consumer group id of the consumer. 
--isolation-level &lt;String&gt;               Set to read_committed in<span> order to      
                                           filter out<span> transactional messages    
                                           which are not committed. Set to      
                                           read_uncommittedto read all          
                                           messages. (default<span>: read_uncommitted)
--key-deserializer &lt;<span>String:                                                     
  deserializer for key&gt;                                                         
--max-messages &lt;Integer: num_messages&gt;<span>   The maximum number of messages to      
                                           consume before exiting. If not set<span>,  
                                           consumption is<span> continual.            
--metrics-dir &lt;String: metrics           If csv-reporter-enable is set<span>, and     
  directory&gt;                               this<span> parameter isset, the csv        
                                           metrics will be output here          
--new-consumer                           Use the new<span> consumer implementation.   
                                           This is the default, so this<span> option  
                                           is deprecated and will be removed in<span> 
                                           a future release.                    
--offset &lt;String: consume offset&gt;        The offset id to consume from (a non-<span>  
                                           negative number), or 'earliest'<span>      
                                           which means from<span> beginning, or       
                                           'latest' which means from<span> end        
                                           (default<span>: latest)                    
--partition &lt;Integer: partition&gt;         The partition to consume from<span>.         
                                           Consumption starts from<span> the end of   
                                           the partition unless '--offset' is<span>   
                                           specified.                           
--property &lt;String: prop&gt;<span>                The properties to initialize the       
                                           message formatter.                   
--skip-message-on-error                  If there is<span> an error when processing a 
                                           message, skip it instead of halt.    
--timeout-ms &lt;Integer: timeout_ms&gt;       If specified, exit if no message is<span>    
                                           available for consumption for<span> the    
                                           specified interval.                  
--topic &lt;String: topic&gt;<span>                  The topic id to consume on.            
--value-deserializer &lt;<span>String:                                                   
  deserializer for values&gt;                                                      
--whitelist &lt;String: whitelist&gt;          Whitelist of topics to include for<span>     
                                           consumption.                         
--zookeeper &lt;String: urls&gt;               <span style="color: #ff0000;">REQUIRED</span> (only when using<span> old          
                                           consumer): The connection string for<span> 
                                           the zookeeper connection in<span> the form 
                                           host:port. Multiple URLS can be      
                                           given to allow fail-over.  </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
</div>
<p>在node22上消费消息(旧命令操作）</p>
<div class="cnblogs_code">
<pre>[admin@node22 kafka_2.11-1.1.0]$ kafka-console-consumer.sh --zookeeper node21:2181,node22:2181,node23:2181&nbsp; --from-beginning --topic TestTopic</pre>
</div>
<p>--from-beginning：会把TestTopic主题中以往所有的数据都读取出来。根据业务场景选择是否增加该配置。</p>
<p><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727183830938-510653726.png" alt="" /></p>
<p>新消费者命令</p>
<div class="cnblogs_code">
<pre>[admin@node22 kafka_2.11-1.1.0]$ kafka-console-consumer.sh --bootstrap-server node21:9092,node22:9092,node23:9092  --from-beginning --topic TestTopic</pre>
</div>
<p><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727184333514-1268844070.png" alt="" /></p>
<h3>4.6删除topic</h3>
<div class="cnblogs_code">
<pre>[admin@node22 kafka_2.11-1.1.0]$ bin/kafka-topics.sh --zookeeper node21:2181,node22:2181,node23:2181  --delete --topic TestTopic</pre>
</div>
<p><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180727184627210-2062234579.png" alt="" /></p>
<p class="20">需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启。</p>
<h3>4.7 停止Kafka服务</h3>
<div class="cnblogs_code">
<pre>[admin@node21 kafka_2.11-1.1.0]$ bin/kafka-server-stop.sh stop</pre>
</div>
<h3><strong>4.8 编写kafka启动脚本</strong></h3>
<div class="cnblogs_code">
<pre>[admin@node21 kafka_2.11-1.1.0<span>]$ cd bin
[admin@node21 bin]$ vi start-<span>kafka.sh
#!/bin/<span>bash
nohup /opt/module/kafka_2.11-1.1.0/bin/kafka-server-start.sh  /opt/module/kafka_2.11-1.1.0/config/server.properties &gt;/opt/module/kafka_2.11-1.1.0/logs/kafka.log 2&gt;&amp;1 &amp;</span></span></span></pre>
</div>
<p><strong>赋权限给脚本：</strong>chmod +x&nbsp;start-kafka.sh</p>
<h2><strong>五</strong>、<strong>Kafka配置信息详解</strong></h2>
<h3><strong>5.1 Broker</strong><strong>配置</strong><strong>信息</strong></h3>
<table border="1" cellspacing="0">
<tbody>
<tr>
<td valign="top" width="182">
<p align="center"><strong>属性</strong></p>
</td>
<td valign="top" width="72">
<p align="center"><strong>默认值</strong></p>
</td>
<td valign="top" width="292">
<p align="center"><strong>描述</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>broker.id</p>
</td>
<td valign="top" width="72">
<p>&nbsp;</p>
</td>
<td valign="top" width="292">
<p>必填参数，broker的唯一标识</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>log.dirs</p>
</td>
<td valign="top" width="72">
<p>/tmp/kafka-logs</p>
</td>
<td valign="top" width="292">
<p>Kafka数据存放的目录。可以指定多个目录，中间用逗号分隔，当新partition被创建的时会被存放到当前存放partition最少的目录。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>port</p>
</td>
<td valign="top" width="72">
<p>9092</p>
</td>
<td valign="top" width="292">
<p>BrokerServer接受客户端连接的端口号</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>zookeeper.connect</p>
</td>
<td valign="top" width="72">
<p>null</p>
</td>
<td valign="top" width="292">
<p>Zookeeper的连接串，格式为：hostname1:port1,hostname2:port2,hostname3:port3。可以填一个或多个，为了提高可靠性，建议都填上。注意，此配置允许我们指定一个zookeeper路径来存放此kafka集群的所有数据，为了与其他应用集群区分开，建议在此配置中指定本集群存放目录，格式为：hostname1:port1,hostname2:port2,hostname3:port3/chroot/path&nbsp;。需要注意的是，消费者的参数要和此参数一致。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>message.max.bytes</p>
</td>
<td valign="top" width="72">
<p>1000000</p>
</td>
<td valign="top" width="292">
<p>服务器可以接收到的最大的消息大小。注意此参数要和consumer的maximum.message.size大小一致，否则会因为生产者生产的消息太大导致消费者无法消费。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>num.io.threads</p>
</td>
<td valign="top" width="72">
<p>8</p>
</td>
<td valign="top" width="292">
<p>服务器用来执行读写请求的IO线程数，此参数的数量至少要等于服务器上磁盘的数量。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>queued.max.requests</p>
</td>
<td valign="top" width="72">
<p>500</p>
</td>
<td valign="top" width="292">
<p>I/O线程可以处理请求的队列大小，若实际请求数超过此大小，网络线程将停止接收新的请求。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>socket.send.buffer.bytes</p>
</td>
<td valign="top" width="72">
<p>100 * 1024</p>
</td>
<td valign="top" width="292">
<p>The SO_SNDBUFF buffer the server prefers for socket connections.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>socket.receive.buffer.bytes</p>
</td>
<td valign="top" width="72">
<p>100 * 1024</p>
</td>
<td valign="top" width="292">
<p>The SO_RCVBUFF buffer the server prefers for socket connections.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>socket.request.max.bytes</p>
</td>
<td valign="top" width="72">
<p>100 * 1024 * 1024</p>
</td>
<td valign="top" width="292">
<p>服务器允许请求的最大值， 用来防止内存溢出，其值应该小于&nbsp;Java heap size.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>num.partitions</p>
</td>
<td valign="top" width="72">
<p>1</p>
</td>
<td valign="top" width="292">
<p>默认partition数量，如果topic在创建时没有指定partition数量，默认使用此值，建议改为5</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>log.segment.bytes</p>
</td>
<td valign="top" width="72">
<p>1024 * 1024 * 1024</p>
</td>
<td valign="top" width="292">
<p>Segment文件的大小，超过此值将会自动新建一个segment，此值可以被topic级别的参数覆盖。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>log.roll.{ms,hours}</p>
</td>
<td valign="top" width="72">
<p>24 * 7 hours</p>
</td>
<td valign="top" width="292">
<p>新建segment文件的时间，此值可以被topic级别的参数覆盖。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>log.retention.{ms,minutes,hours}</p>
</td>
<td valign="top" width="72">
<p>7 days</p>
</td>
<td valign="top" width="292">
<p>Kafka segment log的保存周期，保存周期超过此时间日志就会被删除。此参数可以被topic级别参数覆盖。数据量大时，建议减小此值。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>log.retention.bytes</p>
</td>
<td valign="top" width="72">
<p>-1</p>
</td>
<td valign="top" width="292">
<p>每个partition的最大容量，若数据量超过此值，partition数据将会被删除。注意这个参数控制的是每个partition而不是topic。此参数可以被log级别参数覆盖。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>log.retention.check.interval.ms</p>
</td>
<td valign="top" width="72">
<p>5 minutes</p>
</td>
<td valign="top" width="292">
<p>删除策略的检查周期</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>auto.create.topics.enable</p>
</td>
<td valign="top" width="72">
<p>true</p>
</td>
<td valign="top" width="292">
<p>自动创建topic参数，建议此值设置为false，严格控制topic管理，防止生产者错写topic。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>default.replication.factor</p>
</td>
<td valign="top" width="72">
<p>1</p>
</td>
<td valign="top" width="292">
<p>默认副本数量，建议改为2。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>replica.lag.time.max.ms</p>
</td>
<td valign="top" width="72">
<p>10000</p>
</td>
<td valign="top" width="292">
<p>在此窗口时间内没有收到follower的fetch请求，leader会将其从ISR(in-sync replicas)中移除。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>replica.lag.max.messages</p>
</td>
<td valign="top" width="72">
<p>4000</p>
</td>
<td valign="top" width="292">
<p>如果replica节点落后leader节点此值大小的消息数量，leader节点就会将其从ISR中移除。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>replica.socket.timeout.ms</p>
</td>
<td valign="top" width="72">
<p>30 * 1000</p>
</td>
<td valign="top" width="292">
<p>replica向leader发送请求的超时时间。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>replica.socket.receive.buffer.bytes</p>
</td>
<td valign="top" width="72">
<p>64 * 1024</p>
</td>
<td valign="top" width="292">
<p>The socket receive buffer for network requests to the leader for replicating data.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>replica.fetch.max.bytes</p>
</td>
<td valign="top" width="72">
<p>1024 * 1024</p>
</td>
<td valign="top" width="292">
<p>The number of byes of messages to attempt to fetch for each partition in the fetch requests the replicas send to the leader.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>replica.fetch.wait.max.ms</p>
</td>
<td valign="top" width="72">
<p>500</p>
</td>
<td valign="top" width="292">
<p>The maximum amount of time to wait time for data to arrive on the leader in the fetch requests sent by the replicas to the leader.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>num.replica.fetchers</p>
</td>
<td valign="top" width="72">
<p>1</p>
</td>
<td valign="top" width="292">
<p>Number of threads used to replicate messages from leaders. Increasing this value can increase the degree of I/O parallelism in the follower broker.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>fetch.purgatory.purge.interval.requests</p>
</td>
<td valign="top" width="72">
<p>1000</p>
</td>
<td valign="top" width="292">
<p>The purge interval (in number of requests) of the fetch request purgatory.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>zookeeper.session.timeout.ms</p>
</td>
<td valign="top" width="72">
<p>6000</p>
</td>
<td valign="top" width="292">
<p>ZooKeeper session&nbsp;超时时间。如果在此时间内server没有向zookeeper发送心跳，zookeeper就会认为此节点已挂掉。 此值太低导致节点容易被标记死亡；若太高，.会导致太迟发现节点死亡。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>zookeeper.connection.timeout.ms</p>
</td>
<td valign="top" width="72">
<p>6000</p>
</td>
<td valign="top" width="292">
<p>客户端连接zookeeper的超时时间。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>zookeeper.sync.time.ms</p>
</td>
<td valign="top" width="72">
<p>2000</p>
</td>
<td valign="top" width="292">
<p>H ZK follower落后&nbsp;ZK leader的时间。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>controlled.shutdown.enable</p>
</td>
<td valign="top" width="72">
<p>true</p>
</td>
<td valign="top" width="292">
<p>允许broker shutdown。如果启用，broker在关闭自己之前会把它上面的所有leaders转移到其它brokers上，建议启用，增加集群稳定性。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>auto.leader.rebalance.enable</p>
</td>
<td valign="top" width="72">
<p>true</p>
</td>
<td valign="top" width="292">
<p>If this is enabled the controller will automatically try to balance leadership for partitions among the brokers by periodically returning leadership to the &ldquo;preferred&rdquo; replica for each partition if it is available.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>leader.imbalance.per.broker.percentage</p>
</td>
<td valign="top" width="72">
<p>10</p>
</td>
<td valign="top" width="292">
<p>The percentage of leader imbalance allowed per broker. The controller will rebalance leadership if this ratio goes above the configured value per broker.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>leader.imbalance.check.interval.seconds</p>
</td>
<td valign="top" width="72">
<p>300</p>
</td>
<td valign="top" width="292">
<p>The frequency with which to check for leader imbalance.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offset.metadata.max.bytes</p>
</td>
<td valign="top" width="72">
<p>4096</p>
</td>
<td valign="top" width="292">
<p>The maximum amount of metadata to allow clients to save with their offsets.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>connections.max.idle.ms</p>
</td>
<td valign="top" width="72">
<p>600000</p>
</td>
<td valign="top" width="292">
<p>Idle connections timeout: the server socket processor threads close the connections that idle more than this.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>num.recovery.threads.per.data.dir</p>
</td>
<td valign="top" width="72">
<p>1</p>
</td>
<td valign="top" width="292">
<p>The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>unclean.leader.election.enable</p>
</td>
<td valign="top" width="72">
<p>true</p>
</td>
<td valign="top" width="292">
<p>Indicates whether to enable replicas not in the ISR set to be elected as leader as a last resort, even though doing so may result in data loss.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>delete.topic.enable</p>
</td>
<td valign="top" width="72">
<p>false</p>
</td>
<td valign="top" width="292">
<p>启用deletetopic参数，建议设置为true。</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.topic.num.partitions</p>
</td>
<td valign="top" width="72">
<p>50</p>
</td>
<td valign="top" width="292">
<p>The number of partitions for the offset commit topic. Since changing this after deployment is currently unsupported, we recommend using a higher setting for production (e.g., 100-200).</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.topic.retention.minutes</p>
</td>
<td valign="top" width="72">
<p>1440</p>
</td>
<td valign="top" width="292">
<p>Offsets that are older than this age will be marked for deletion. The actual purge will occur when the log cleaner compacts the offsets topic.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.retention.check.interval.ms</p>
</td>
<td valign="top" width="72">
<p>600000</p>
</td>
<td valign="top" width="292">
<p>The frequency at which the offset manager checks for stale offsets.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.topic.replication.factor</p>
</td>
<td valign="top" width="72">
<p>3</p>
</td>
<td valign="top" width="292">
<p>The replication factor for the offset commit topic. A higher setting (e.g., three or four) is recommended in order to ensure higher availability. If the offsets topic is created when fewer brokers than the replication factor then the offsets topic will be created with fewer replicas.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.topic.segment.bytes</p>
</td>
<td valign="top" width="72">
<p>104857600</p>
</td>
<td valign="top" width="292">
<p>Segment size for the offsets topic. Since it uses a compacted topic, this should be kept relatively low in order to facilitate faster log compaction and loads.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.load.buffer.size</p>
</td>
<td valign="top" width="72">
<p>5242880</p>
</td>
<td valign="top" width="292">
<p>An offset load occurs when a broker becomes the offset manager for a set of consumer groups (i.e., when it becomes a leader for an offsets topic partition). This setting corresponds to the batch size (in bytes) to use when reading from the offsets segments when loading offsets into the offset manager&rsquo;s cache.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.commit.required.acks</p>
</td>
<td valign="top" width="72">
<p>-1</p>
</td>
<td valign="top" width="292">
<p>The number of acknowledgements that are required before the offset commit can be accepted. This is similar to the producer&rsquo;s acknowledgement setting. In general, the default should not be overridden.</p>
</td>
</tr>
<tr>
<td valign="top" width="182">
<p>offsets.commit.timeout.ms</p>
</td>
<td valign="top" width="72">
<p>5000</p>
</td>
<td valign="top" width="292">
<p>The offset commit will be delayed until this timeout or the required number of replicas have received the offset commit. This is similar to the producer request timeout.</p>
</td>
</tr>
</tbody>
</table>
<h3><strong>5.2 Producer</strong><strong>配置信息</strong></h3>
<table border="1" cellspacing="0">
<tbody>
<tr>
<td valign="top" width="179">
<p align="center"><strong>属性</strong></p>
</td>
<td valign="top" width="75">
<p align="center"><strong>默认值</strong></p>
</td>
<td valign="top" width="292">
<p align="center"><strong>描述</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>metadata.broker.list</p>
</td>
<td valign="top" width="75">
<p>&nbsp;</p>
</td>
<td valign="top" width="292">
<p>启动时producer查询brokers的列表，可以是集群中所有brokers的一个子集。注意，这个参数只是用来获取topic的元信息用，producer会从元信息中挑选合适的broker并与之建立socket连接。格式是：host1:port1,host2:port2。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>request.required.acks</p>
</td>
<td valign="top" width="75">
<p>0</p>
</td>
<td valign="top" width="292">
<p>参见3.2节介绍</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>request.timeout.ms</p>
</td>
<td valign="top" width="75">
<p>10000</p>
</td>
<td valign="top" width="292">
<p>Broker等待ack的超时时间，若等待时间超过此值，会返回客户端错误信息。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>producer.type</p>
</td>
<td valign="top" width="75">
<p>sync</p>
</td>
<td valign="top" width="292">
<p>同步异步模式。async表示异步，sync表示同步。如果设置成异步模式，可以允许生产者以batch的形式push数据，这样会极大的提高broker性能，推荐设置为异步。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>serializer.class</p>
</td>
<td valign="top" width="75">
<p>kafka.serializer.DefaultEncoder</p>
</td>
<td valign="top" width="292">
<p>序列号类，.默认序列化成&nbsp;byte[]&nbsp;。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>key.serializer.class</p>
</td>
<td valign="top" width="75">
<p>&nbsp;</p>
</td>
<td valign="top" width="292">
<p>Key的序列化类，默认同上。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>partitioner.class</p>
</td>
<td valign="top" width="75">
<p>kafka.producer.DefaultPartitioner</p>
</td>
<td valign="top" width="292">
<p>Partition类，默认对key进行hash。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>compression.codec</p>
</td>
<td valign="top" width="75">
<p>none</p>
</td>
<td valign="top" width="292">
<p>指定producer消息的压缩格式，可选参数为：&nbsp;&ldquo;none&rdquo;, &ldquo;gzip&rdquo; and &ldquo;snappy&rdquo;。关于压缩参见4.1节</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>compressed.topics</p>
</td>
<td valign="top" width="75">
<p>null</p>
</td>
<td valign="top" width="292">
<p>启用压缩的topic名称。若上面参数选择了一个压缩格式，那么压缩仅对本参数指定的topic有效，若本参数为空，则对所有topic有效。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>message.send.max.retries</p>
</td>
<td valign="top" width="75">
<p>3</p>
</td>
<td valign="top" width="292">
<p>Producer发送失败时重试次数。若网络出现问题，可能会导致不断重试。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>retry.backoff.ms</p>
</td>
<td valign="top" width="75">
<p>100</p>
</td>
<td valign="top" width="292">
<p>Before each retry, the producer refreshes the metadata of relevant topics to see if a new leader has been elected. Since leader election takes a bit of time, this property specifies the amount of time that the producer waits before refreshing the metadata.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>topic.metadata.refresh.interval.ms</p>
</td>
<td valign="top" width="75">
<p>600 * 1000</p>
</td>
<td valign="top" width="292">
<p>The producer generally refreshes the topic metadata from brokers when there is a failure (partition missing, leader not available&hellip;). It will also poll regularly (default: every 10min so 600000ms). If you set this to a negative value, metadata will only get refreshed on failure. If you set this to zero, the metadata will get refreshed after each message sent (not recommended). Important note: the refresh happen only AFTER the message is sent, so if the producer never sends a message the metadata is never refreshed</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>queue.buffering.max.ms</p>
</td>
<td valign="top" width="75">
<p>5000</p>
</td>
<td valign="top" width="292">
<p>启用异步模式时，producer缓存消息的时间。比如我们设置成1000时，它会缓存1秒的数据再一次发送出去，这样可以极大的增加broker吞吐量，但也会造成时效性的降低。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>queue.buffering.max.messages</p>
</td>
<td valign="top" width="75">
<p>10000</p>
</td>
<td valign="top" width="292">
<p>采用异步模式时producer buffer&nbsp;队列里最大缓存的消息数量，如果超过这个数值，producer就会阻塞或者丢掉消息。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>queue.enqueue.timeout.ms</p>
</td>
<td valign="top" width="75">
<p>-1</p>
</td>
<td valign="top" width="292">
<p>当达到上面参数值时producer阻塞等待的时间。如果值设置为0，buffer队列满时producer不会阻塞，消息直接被丢掉。若值设置为-1，producer会被阻塞，不会丢消息。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>batch.num.messages</p>
</td>
<td valign="top" width="75">
<p>200</p>
</td>
<td valign="top" width="292">
<p>采用异步模式时，一个batch缓存的消息数量。达到这个数量值时producer才会发送消息。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>send.buffer.bytes</p>
</td>
<td valign="top" width="75">
<p>100 * 1024</p>
</td>
<td valign="top" width="292">
<p>Socket write buffer size</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>client.id</p>
</td>
<td valign="top" width="75">
<p>&ldquo;&rdquo;</p>
</td>
<td valign="top" width="292">
<p>The client id is a user-specified string sent in each request to help trace calls. It should logically identify the application making the request.</p>
</td>
</tr>
</tbody>
</table>
<h3><strong>5.3 Consumer</strong><strong>配置信息</strong></h3>
<table border="1" cellspacing="0">
<tbody>
<tr>
<td valign="top" width="179">
<p align="center"><strong>属性</strong></p>
</td>
<td valign="top" width="75">
<p align="center"><strong>默认值</strong></p>
</td>
<td valign="top" width="292">
<p align="center"><strong>描述</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>group.id</p>
</td>
<td valign="top" width="75">
<p>&nbsp;</p>
</td>
<td valign="top" width="292">
<p>Consumer的组ID，相同goup.id的consumer属于同一个组。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>zookeeper.connect</p>
</td>
<td valign="top" width="75">
<p>&nbsp;</p>
</td>
<td valign="top" width="292">
<p>Consumer的zookeeper连接串，要和broker的配置一致。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>consumer.id</p>
</td>
<td valign="top" width="75">
<p>null</p>
</td>
<td valign="top" width="292">
<p>如果不设置会自动生成。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>socket.timeout.ms</p>
</td>
<td valign="top" width="75">
<p>30 * 1000</p>
</td>
<td valign="top" width="292">
<p>网络请求的socket超时时间。实际超时时间由max.fetch.wait + socket.timeout.ms&nbsp;确定。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>socket.receive.buffer.bytes</p>
</td>
<td valign="top" width="75">
<p>64 * 1024</p>
</td>
<td valign="top" width="292">
<p>The socket receive buffer for network requests.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>fetch.message.max.bytes</p>
</td>
<td valign="top" width="75">
<p>1024 * 1024</p>
</td>
<td valign="top" width="292">
<p>查询topic-partition时允许的最大消息大小。consumer会为每个partition缓存此大小的消息到内存，因此，这个参数可以控制consumer的内存使用量。这个值应该至少比server允许的最大消息大小大，以免producer发送的消息大于consumer允许的消息。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>num.consumer.fetchers</p>
</td>
<td valign="top" width="75">
<p>1</p>
</td>
<td valign="top" width="292">
<p>The number fetcher threads used to fetch data.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>auto.commit.enable</p>
</td>
<td valign="top" width="75">
<p>true</p>
</td>
<td valign="top" width="292">
<p>如果此值设置为true，consumer会周期性的把当前消费的offset值保存到zookeeper。当consumer失败重启之后将会使用此值作为新开始消费的值。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>auto.commit.interval.ms</p>
</td>
<td valign="top" width="75">
<p>60 * 1000</p>
</td>
<td valign="top" width="292">
<p>Consumer提交offset值到zookeeper的周期。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>queued.max.message.chunks</p>
</td>
<td valign="top" width="75">
<p>2</p>
</td>
<td valign="top" width="292">
<p>用来被consumer消费的message chunks&nbsp;数量， 每个chunk可以缓存fetch.message.max.bytes大小的数据量。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>auto.commit.interval.ms</p>
</td>
<td valign="top" width="75">
<p>60 * 1000</p>
</td>
<td valign="top" width="292">
<p>Consumer提交offset值到zookeeper的周期。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>queued.max.message.chunks</p>
</td>
<td valign="top" width="75">
<p>2</p>
</td>
<td valign="top" width="292">
<p>用来被consumer消费的message chunks&nbsp;数量， 每个chunk可以缓存fetch.message.max.bytes大小的数据量。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>fetch.min.bytes</p>
</td>
<td valign="top" width="75">
<p>1</p>
</td>
<td valign="top" width="292">
<p>The minimum amount of data the server should return for a fetch request. If insufficient data is available the request will wait for that much data to accumulate before answering the request.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>fetch.wait.max.ms</p>
</td>
<td valign="top" width="75">
<p>100</p>
</td>
<td valign="top" width="292">
<p>The maximum amount of time the server will block before answering the fetch request if there isn&rsquo;t sufficient data to immediately satisfy fetch.min.bytes.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>rebalance.backoff.ms</p>
</td>
<td valign="top" width="75">
<p>2000</p>
</td>
<td valign="top" width="292">
<p>Backoff time between retries during rebalance.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>refresh.leader.backoff.ms</p>
</td>
<td valign="top" width="75">
<p>200</p>
</td>
<td valign="top" width="292">
<p>Backoff time to wait before trying to determine the leader of a partition that has just lost its leader.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>auto.offset.reset</p>
</td>
<td valign="top" width="75">
<p>largest</p>
</td>
<td valign="top" width="292">
<p>What to do when there is no initial offset in ZooKeeper or if an offset is out of range ;smallest : automatically reset the offset to the smallest offset; largest : automatically reset the offset to the largest offset;anything else: throw exception to the consumer</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>consumer.timeout.ms</p>
</td>
<td valign="top" width="75">
<p>-1</p>
</td>
<td valign="top" width="292">
<p>若在指定时间内没有消息消费，consumer将会抛出异常。</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>exclude.internal.topics</p>
</td>
<td valign="top" width="75">
<p>true</p>
</td>
<td valign="top" width="292">
<p>Whether messages from internal topics (such as offsets) should be exposed to the consumer.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>zookeeper.session.timeout.ms</p>
</td>
<td valign="top" width="75">
<p>6000</p>
</td>
<td valign="top" width="292">
<p>ZooKeeper session timeout. If the consumer fails to heartbeat to ZooKeeper for this period of time it is considered dead and a rebalance will occur.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>zookeeper.connection.timeout.ms</p>
</td>
<td valign="top" width="75">
<p>6000</p>
</td>
<td valign="top" width="292">
<p>The max time that the client waits while establishing a connection to zookeeper.</p>
</td>
</tr>
<tr>
<td valign="top" width="179">
<p>zookeeper.sync.time.ms</p>
</td>
<td valign="top" width="75">
<p>2000</p>
</td>
<td valign="top" width="292">
<p>How far a ZK follower can be behind a ZK leader</p>
<p>&nbsp;</p>
</td>
</tr>
</tbody>
</table></div>

</body>
</html>
